﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.mediator;
using SharpSqlAnalyzer.pp.mediator.type;
using SharpSqlAnalyzer.pp.utils;

namespace SharpSqlAnalyzer.pp.processor.type.comm
{
	// Token: 0x0200024E RID: 590
	public class AppendNewLineBeforeKeyWordProcessor : AbstractProcessor
	{
		// Token: 0x06001321 RID: 4897 RVA: 0x0031CD5C File Offset: 0x0031AF5C
		public override void process(TParseTreeNode node)
		{
			bool parameter = this.getParameter<bool>(typeof(bool));
			string parameter2 = this.getParameter<string>(typeof(string), 1);
			bool? flag = new bool?(this.getParameter<bool>(typeof(bool), 2));
			TSourceToken tsourceToken = SourceTokenSearcher.forwardSearch(node.startToken, (flag != null) ? (node.endToken.posinlist - node.startToken.posinlist) : 5, parameter2);
			if (tsourceToken != null)
			{
				int num = 0;
				KeywordAlignMediator mediator = MediatorFactory.getMediator<KeywordAlignMediator>(typeof(KeywordAlignMediator), this.Option.sessionId);
				if (mediator.CurLevelIndentLen > num)
				{
					num = mediator.CurLevelIndentLen;
				}
				mediator.addIndentLevelItem(tsourceToken, num);
				SourceTokenOperator.removeWhitespaceAndReturnFromEnd(this.Option, tsourceToken.container, tsourceToken.posinlist);
				if (parameter)
				{
					SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createReturnSourceToken());
					SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenOperator.createWhitespaceSourceToken(num + this.Option.indentLen));
					return;
				}
				SourceTokenOperator.addBefore(this.Option, tsourceToken, SourceTokenConstant.WHITESPACE);
			}
		}
	}
}
